package com.example.design.a.builder;

import lombok.Getter;
import lombok.Setter;
import org.thymeleaf.util.StringUtils;

/**
 * 电脑实体
 */
@Setter
@Getter
public class Computer {
    /**
     * 电脑名称
     */
    private String name;
    /**
     * 显示器
     */
    private Screen screen;
    /**
     * 鼠标
     */
    private Mouse mouse;
    /**
     * 键盘
     */
    private Keyboard keyboard;

    @Override
    public String toString() {
        if (StringUtils.isEmpty(name)) {
            name = "未知品牌";
        }
        if (screen == null) {
            screen = new Screen("杂牌");
        }
        if (mouse == null) {
            mouse = new Mouse("杂牌");
        }
        if (keyboard == null) {
            keyboard = new Keyboard("杂牌");
        }
        String temp = "%s电脑采用%s键盘, %s牌鼠标, 并采用%s显示器";
        return String.format(temp, name, keyboard.getName(), mouse.getName(), screen.getName());
    }
}
